package com.itheima.config;


import org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.StringRedisSerializer;

@Configuration
public class RedisConfig extends RedisAutoConfiguration {

    /**
     * 此处配置redis的序列化方法
     * 此处可以通过RedisAutoConfiguration复制方法
     */
    @Bean
    public RedisTemplate<Object, Object> redisTemplate(RedisConnectionFactory redisConnectionFactory) {
        //创建一个redisTemplate对象
        RedisTemplate<Object, Object> redisTemplate = new RedisTemplate<>();
        //此处配置Key String序列化
        redisTemplate.setKeySerializer(new StringRedisSerializer());
        //配置工厂
        redisTemplate.setConnectionFactory(redisConnectionFactory);
        return redisTemplate;
    }

}
